﻿using Microsoft.Office.Tools.Ribbon;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PowerPoint = Microsoft.Office.Interop.PowerPoint;
using Office = Microsoft.Office.Core;
using System.Windows.Forms;

namespace PPTHelper
{
    public partial class Ribbon1
    {
        PowerPoint.Application app;

        /// <summary>
        /// 厘米到磅的换算，将厘米乘以这个数即可得到磅数
        /// </summary>
        public float CentimetersToPounds = 28.35f;


        private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
        {
            app = Globals.ThisAddIn.Application;
        }

        private void button1_Click(object sender, RibbonControlEventArgs e)
        {
            PowerPoint.Selection sel = app.ActiveWindow.Selection; //获取当前选择的所有内容，可以是形状也可以是某一张幻灯片
            PowerPoint.SlideRange selSlide = sel.SlideRange; // 获取选择的幻灯片
            if (sel.Type != PowerPoint.PpSelectionType.ppSelectionShapes) //判断是否选中了图形
            {
                MessageBox.Show("请选择一张图片", "提示");
                return;
            }

            if (sel.HasChildShapeRange)
            {
                //当选择的图片在组里时使用ChildShapeRange方法获取选取的物体
                foreach (PowerPoint.Shape item in sel.ChildShapeRange) 
                {
                    if (item.Type == Office.MsoShapeType.msoPicture) // 判断选中的是否是图片
                    {
                        PPTTools.PictureChange(selSlide, item, sel.ShapeRange); // 使用 ShapeRange获取这个组
                    }
                }

            }
            else
            {
                foreach (PowerPoint.Shape item in sel.ShapeRange)
                {
                    if (item.Type == Office.MsoShapeType.msoPicture)
                    {
                        PPTTools.PictureChange(selSlide, item); // 组外直接替换就行
                    }
                }
            }
        }
    }
}
